package top.bigdata.service.request;

import org.springframework.stereotype.Service;
import top.bigdata.model.dto.author.MonthlyAuthor;
import top.bigdata.model.entity.Author;

import java.util.LinkedHashMap;

@Service
public class UserInfoService {
    /**
     *  获取作者信息
     */
    public Author getUserInfo(long mid) {
        var userInfo = (LinkedHashMap) HttpInterface.get("https://api.bilibili.com/x/web-interface/card?mid=" + mid).get("data");
        var card = (LinkedHashMap) userInfo.get("card");
        return new Author(
                mid,
                (String) card.get("name"),
                (String) card.get("sex"),
                (String) card.get("face"),
                (Integer) card.get("fans"),
                null
        );
    }

    /**
     *  将作者信息复制到月度数据中
     */
    public void copyAuthorFields(Author src, MonthlyAuthor dest) {
        dest.setMid(src.getMid());
        dest.setName(src.getName());
        dest.setSex(src.getSex());
        dest.setFace(src.getFace());
        dest.setFollower(src.getFollower());
    }
}
